import QtQuick 1.1
import com.nokia.meego 1.0
import "Logger.js" as Logger

ToolBarLayout {
  id: defaultTools

  property string previousViewName: "feedView"

  ToolIcon {
    enabled: appState.feedItemView ? true : false
    iconId: enabled ? "toolbar-back" : "toolbar-back-dimmed"
    onClicked: {
      if (appState.feedItemView) {
        var viewName = appState.currentViewName;
        Logger.log("Back-button clicked. Came from view: " + viewName);
        if (viewName === "feedItemView") {
          appState.currentViewName = "feedView";
        } else if (viewName === "settingsView") {
          // Return to the previous view.
          appState.currentViewName = defaultTools.previousViewName;
        }
        pageStack.pop();
      } else {
        // In Harmattan we don't exit.
      }
    }
  }

  ToolIcon {
    enabled: appState.feedItemView ? false : true
    iconId: enabled ? "toolbar-refresh" : "toolbar-refresh-dimmed"
    onClicked: {
      waitIndicator.show = true;
      waitIndicator.delay = 0;
      appState.feedModel.reload();
    }
  }

  ToolIcon {
    enabled: appState.feedItemView && appState.currentIndex > 0 ? true : false
    iconId: enabled ? "toolbar-previous" : "toolbar-previous-dimmed"
    onClicked: {
      appState.currentIndex = appState.currentIndex - 1;
    }
  }

  ToolIcon {
    enabled: appState.feedItemView && appState.currentIndex < appState.feedModel.count - 1 ? true : false
    iconId: enabled ? "toolbar-next" : "toolbar-next-dimmed"
    onClicked: {
      appState.currentIndex = appState.currentIndex + 1;
    }
  }

  ToolIcon {
    iconId: "toolbar-settings"
  }
}